主题
按设备名打开摄像头 - OpenCameraByName
函数简介
按设备友好名、DirectShow 的 video=... 串,或 Linux 下的设备路径(如 /dev/video0)打开摄像头,返回视频句柄。
接口名称
OpenCameraByNameDLL调用
c
OLA_HANDLE_RETURN OLA_CALL_TYPE OpenCameraByName(int64_t instance, OLA_STRING_INPUT deviceName);参数说明
| 参数名 | 类型 | 说明 |
|---|---|---|
| instance | 长整数型 | OLAPlug对象的指针,由 CreateCOLAPlugInterFace 接口生成。 |
| deviceName | 文本型 | 设备友好名、DirectShow 的 video=... 串,或 Linux 下如 /dev/video0 等设备路径。 |
示例
SDK 调用
cpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
long handle = ola.OpenCameraByName("video=...");csharp
using OLAPlug;
var ola = new OLAPlugServer();
long handle = ola.OpenCameraByName("video=...");python
from OLAPlugServer import OLAPlugServer
ola = OLAPlugServer()
handle = ola.OpenCameraByName("video=...")java
import com.olaplug.OLAPlugServer;
OLAPlugServer ola = new OLAPlugServer();
long handle = ola.OpenCameraByName("video=...");cpp
var ola = com("OlaPlug.OlaSoft")
var handle = ola.OpenCameraByName("video=...")vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")
handle = ola.OpenCameraByName("video=...")text
.局部变量 ola, OLAPlug
ola.创建 ()
handle = ola.OpenCameraByName("video=...")aardio
import OLAPlugServer;
var ola = OLAPlugServer();
var handle = ola.OpenCameraByName("video=...");text
变量 ola <类型 = OLAPlugServer>
ola = 新建 OLAPlugServer
长整数 handle = ola.OpenCameraByName("video=...")cpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
long handle = ola.OpenCameraByName("video=...");原生 DLL 调用
cpp
OpenCameraByName(instance, "video=...");csharp
using System.Runtime.InteropServices;
using System.Text;
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int OpenCameraByName(long ola, string deviceName);
OpenCameraByName(instance, "video=...");python
from ctypes import CDLL, c_int, c_int64, create_string_buffer
ola = CDLL("OLAPlug_x64.dll")
ola.CreateCOLAPlugInterFace.restype = c_int64
ola.OpenCameraByName(instance, "video=...")返回值
| 返回值 | 说明 |
|---|---|
| (返回值) | 长整数型:视频句柄,失败返回 0。 |
注意事项
| 项目 | 说明 |
|---|---|
| Windows 下会优先尝试 DirectSho | Windows 下会优先尝试 DirectShow(video=设备名),失败再尝试默认后端。 |
| 句柄用于后续的视频操作 | 返回的句柄用于后续的视频操作,使用完毕后需调用 CloseVideo 释放。 |
| 目标设备已连接且未被其他程序占用 | 确保目标设备已连接且未被其他程序占用。 |
